import { TableBase, TextTable } from '@/components/public-template';
import dayjs from 'dayjs';

class HomeService {
  // 档案生命周期
  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'code',
        value: '单据编码'
      }),
      new TextTable({
        key: 'billType',
        value: '单据类型',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_LIFE_CYCLE_BILL_TYPE'
        }
      }),
      new TextTable({
        key: 'creatorName',
        value: '申请人'
      }),
      new TextTable({
        key: 'reviewStartTime',
        value: '开始审核时间'
      }),
      new TextTable({
        key: 'reviewEndTime',
        value: '结束审核时间'
      })
    ];
    return tables;
  }

  // 迁移记录
  getPrintTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'code',
        value: '单据编码'
      }),
      new TextTable({
        key: 'oldLocation',
        value: '原存放地点'
      }),
      new TextTable({
        key: 'newLocation',
        value: '新存放地点'
      }),
      new TextTable({
        key: 'reason',
        value: '迁移原因'
      }),
      new TextTable({
        key: 'creatorName',
        value: '申请人'
      }),
      new TextTable({
        key: 'createTime',
        value: '申请时间'
      })
    ];
    return tables;
  }

  // 盘点记录
  getCheckTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'inventoryResult',
        value: '盘点结果'
      }),
      new TextTable({
        key: 'resultExplain',
        value: '说明'
      }),
      new TextTable({
        key: 'exceptionHandling',
        value: '异常处理',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_INVENTORY_EXCEPTION_HANDLING'
        }
      }),
      new TextTable({
        key: 'inventoryUserName',
        value: '盘点人'
      }),
      new TextTable({
        key: 'creatorName',
        value: '申请人'
      }),
      new TextTable({
        key: 'createTime',
        value: '申请时间'
      })
    ];
    return tables;
  }

  // 借阅记录
  getBorrowTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'borrowCode',
        value: '借阅编码'
      }),
      new TextTable({
        key: 'borrowType',
        value: '借阅类型',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_BORROW_BORROW_TYPE'
        }
      }),
      new TextTable({
        key: 'borrowerName',
        value: '借阅人'
      }),
      new TextTable({
        key: 'borrowTime',
        value: '借阅时间'
      }),
      new TextTable({
        key: 'renewTime',
        value: '续借时间'
      }),
      new TextTable({
        key: 'planReturnTime',
        value: '计划归还时间'
      }),
      new TextTable({
        key: 'actualReturnTime',
        value: '实际归还时间'
      }),
      new TextTable({
        value: '是否逾期',
        type: 'custom',
        columns: {
          customRender: ({ text, record, index }) => {
            if (record.actualReturnTime ?? '' !== '') {
              if (dayjs(record.actualReturnTime).unix() > dayjs(record.planReturnTime).unix()) {
                return '是';
              } else {
                return '否';
              }
            } else {
              return '';
            }
          }
        }
      })
    ];
    return tables;
  }

  // 操作记录
  getOperateTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'type',
        value: '操作类型',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_OPT_PERMISSION'
        }
      }),
      new TextTable({
        key: 'operatorName',
        value: '操作人'
      }),
      new TextTable({
        key: 'time',
        value: '操作时间'
      })
    ];
    return tables;
  }
}

export default new HomeService();
